raw=input().split(" ")
[n,e]=[int(i) for i in raw]
raw=input().split(" ")
heights=[int(i) for i in raw]
links=[[] for _ in range(n+1)]
for _ in range(e):
    raw=input().split(" ")
    [i,j]=[int(n) for n in raw]
    if heights[i-1]>heights[j-1]:
        links[i].append(j)
    if heights[i-1]<heights[j-1]:
        links[j].append(i)

result=0
temp={}

def dfs(node):
    maxr=1
    for i in links[node]:
        if i in temp:
            maxr=max(maxr,temp[i]+1)
        else:
            t=dfs(i)
            maxr=max(t,maxr)
    temp[node]=maxr
    return maxr
for i in range(1,n+1):
    result=max(result,dfs(i))

print(result)

